#!usr/bin/env python  
#@time: 2018/01/19 
from multiprocessing import Pool
import os, time, random

def long_time_task(name):
    print('开启任务 %s (%s)...' % (name, os.getpid()))
    start = time.time()
    time.sleep(random.random()*3)
    # print(random.random())
    end = time.time()
    print('任务 %s 运行了 %0.2f 秒' %(name, (end - start)))

if __name__ == '__main__':
    print('父进程 %s.' % os.getpid())
    p = Pool(5)

    for i in range(5):
        # print('i: %s' %i)
        p.apply_async(long_time_task, args=(i,))
    print(' 等待 所有子进程 结束')

    p.close()
    p.join()
    print('所有子进程结束')